import { Component, Input } from '@angular/core';
import { CascaderItem } from 'ng-devui';
import { PutDepartment } from 'src/app/@core/data/Department';
@Component({
  selector: 'app-edit-store-house-categroy',
  templateUrl: './edit-store-house-categroy.component.html',
  styleUrls: ['./edit-store-house-categroy.component.scss']
})
export class EditStoreHouseCategroyComponent {
  @Input() data: any;
  options: any;//仓库
  warehouseCategory = {
    warehouseCategoryName: '',
    parentWarehouseCategoryId: null,
  };//新增部门
  currentSelectedItem = '启用';
  ngOnInit(): void {
    this.warehouseCategory.warehouseCategoryName = this.data.option.warehouseCategoryName
    this.warehouseCategory.parentWarehouseCategoryId = this.data.option.parentWarehouseCategoryId
    this.options = this.convertToCascaderItem(this.data.options)
    if (this.data.pathPids.legth > 1) {
      this.warehouseCategory.parentWarehouseCategoryId = this.data.pathPids[this.data.pathPids.length - 1]
    }
  }
  convertToCascaderItem(data: any[]): CascaderItem[] {
    return data.map(item => {
      let cascaderItem: CascaderItem = {
        label: item.warehouseCategoryName,
        value: item.warehouseCategoryId,
        icon: item.icon
      };
      if (item.subWarehouseCategories) {
        cascaderItem.children = this.convertToCascaderItem(item.subWarehouseCategories);
      }
      return cascaderItem;
    });
  }//转换数据格式为华为库练级菜单的数据格式
  onChanges($event: string | any[]) {
    this.warehouseCategory.parentWarehouseCategoryId = $event[$event.length - 1]
  }
}
